#!/usr/bin/env bash
function usage
{
    echo ""
    echo "Bash scripting creator ver $VERSION"
    echo "Usage: $0 <filename>"
    echo "e.g    $0 testtool.sh"
    echo ""
    exit 1
}

VERSION="20111026"
MAXARG=1

echo Number of arguments passed: $#
if [ $# -gt $MAXARG ] || [ $# -eq 0 ]; then
    usage;
fi

if [ $1 = "" ]; then
    echo "Invalid file name!"
    usage;
fi    

filename="$1";

function add_bash_interpreter
{
    bash_string="#!/usr/bin/env bash"
    echo $bash_string > $filename
}

function change_mode_execution
{
    if [ -e $filename ]; then
        chmod +x $filename;
    else
        echo "File not found!"
    fi
}

function add_exit_eof
{
    exit_string="exit 0;"

    echo "          " >> $filename
    echo "          " >> $filename
    echo "          " >> $filename
    echo $exit_string >> $filename
}

add_bash_interpreter;

change_mode_execution;

add_exit_eof;

exit 0;
